var httpd 		= require("./core/backend/httpd"),
	directory 	= require("./core/backend/directory"),
	site		= require("./site/site");
	sys			= require("sys");

process.addListener('uncaughtException', function (err) {
  sys.log('Caught exception: ' + err);
});

var my = httpd.createHttpd();
my.disk.addDirectory(
	directory.createDirectory("/", "site/root/")
);
my.disk.addDirectory(
	directory.createFunctionDirectory("/status", 
		function (request, response, fn) {
			var data =	"<h1>Status</h1>" +
						"<p>rss: " +
						Math.round((process.memoryUsage().rss)/1024) +
						" KB</p>" +
						"<p>vsize: " +
						Math.round((process.memoryUsage().vsize)/1024) +
						" KB</p>";
			fn(null, {code: 200,
				header: {"Content-type": "text/html; charset=utf-8",
					 	 "Content-length": data.length},
				body: data});
		}
	)
);
my.disk.addDirectory(
	directory.createFunctionDirectory("/shootpike/getdata", 
		function (request, response, fn) {
			var data = JSON.stringify(site.getData());
			fn(null, {code: 200,
				header: {"Content-type": "text/plain",
					 	 "Content-length": data.length},
				body: data});
		}
	)
);

site.site();